package xyz.bali16.module.netdisk.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.bali16.module.netdisk.entity.FileUser;
import xyz.bali16.module.netdisk.mapper.FileUserMapper;
import xyz.bali16.module.netdisk.model.fileuser.FileUserAddParam;
import xyz.bali16.module.netdisk.model.fileuser.FileUserPageParam;
import xyz.bali16.module.netdisk.model.fileuser.FileUserUpdateParam;
import xyz.bali16.module.netdisk.service.FileUserService;


/**
 * @author bali2 on 31/10/2021.
 * @version 1.0
 */
@Service("fileUserService")
public class FileUserServiceImpl extends ServiceImpl<FileUserMapper, FileUser> implements FileUserService {

    @Override
    public IPage<FileUser> getPage(FileUserPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getPage(page, param.getId(),param.getUserId(),param.getFileStorageId());
    }

    @Override
    public FileUser getFileUserBySysUserId(String userId) {
        return baseMapper.getFileUserBySysUserId(userId);
    }

    @Override
    public void add(FileUserAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "FileUserAddParam 参数不能为为空");
        FileUser fileUser = new FileUser();
        BeanUtils.copyProperties(param, fileUser);
        save(fileUser);
    }

    @Override
    public void update(FileUserUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "FileUserUpdateParam 参数不能为为空");
        FileUser fileUser = new FileUser();
        BeanUtils.copyProperties(param, fileUser);
        updateById(fileUser);
    }

    @Override
    public void delete(String fileUserId) throws Exception {
        if (fileUserId == null) {
            return;
        }
        removeById(fileUserId);
    }

}
